/*
** Copyright (C) 2010 Calin Radoni
**
** This file is part of CHScanner.
**
** CHScanner is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CHScanner is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CHScanner. If not, see <http://www.gnu.org/licenses/>.
*/

#include "StdAfx.h"
#include "MSTPPacket.h"

//---------------------------------------------------------------------------

MSTPPacket::MSTPPacket(void)
{
	Initialize();
}

MSTPPacket::~MSTPPacket(void)
{
}

//---------------------------------------------------------------------------

void MSTPPacket::Initialize(void)
{
	ProtocolId       = 0xFFFF;
	Version          = 0;
	MessageType      = 0;
	Flags            = 0;
	RootIdPriority   = 0;
	RootPathCost     = 0;
	BridgeIdPriority = 0;
	PortId           = 0;
	MessageAge       = 0;
	MaximumAge       = 0;
	HelloTime        = 0;
	ForwardDelay     = 0;

	for(int i=0; i<6; i++){
		RootIdMAC[i]   = 0;
		BridgeIdMAC[i] = 0;
	}
}

bool MSTPPacket::IsEmpty(void)
{
	return ProtocolId==0xFFFF ? true : false;
}

//---------------------------------------------------------------------------

bool MSTPPacket::LoadFromPointer(MSTPPacket* packIn)
{
	Initialize();
	if(packIn==NULL) return true;

	ProtocolId       = packIn->ProtocolId;
	Version          = packIn->Version;
	MessageType      = packIn->MessageType;
	Flags            = packIn->Flags;
	RootIdPriority   = packIn->RootIdPriority;
	RootPathCost     = packIn->RootPathCost;
	BridgeIdPriority = packIn->BridgeIdPriority;
	PortId           = packIn->PortId;
	MessageAge       = packIn->MessageAge;
	MaximumAge       = packIn->MaximumAge;
	HelloTime        = packIn->HelloTime;
	ForwardDelay     = packIn->ForwardDelay;

	for(int i=0; i<6; i++){
		RootIdMAC[i]   = packIn->RootIdMAC[i];
		BridgeIdMAC[i] = packIn->BridgeIdMAC[i];
	}

	return true;
}

//---------------------------------------------------------------------------

bool MSTPPacket::IsEqualWith(MSTPPacket* packIn)
{
	bool theSame;

	if(packIn==NULL) return false;

	if(ProtocolId       != packIn->ProtocolId)       return false;
	if(Version          != packIn->Version)          return false;
	if(MessageType      != packIn->MessageType)      return false;
	if(Flags            != packIn->Flags)            return false;
	if(RootIdPriority   != packIn->RootIdPriority)   return false;
	if(RootPathCost     != packIn->RootPathCost)     return false;
	if(BridgeIdPriority != packIn->BridgeIdPriority) return false;
	if(PortId           != packIn->PortId)           return false;
	if(MessageAge       != packIn->MessageAge)       return false;
	if(MaximumAge       != packIn->MaximumAge)       return false;
	if(HelloTime        != packIn->HelloTime)        return false;
	if(ForwardDelay     != packIn->ForwardDelay)     return false;

	theSame = true;
	for(int i=0; i<6 && theSame; i++){
		if(RootIdMAC[i]   != packIn->RootIdMAC[i])   theSame = false;
		if(BridgeIdMAC[i] != packIn->BridgeIdMAC[i]) theSame = false;
	}

	return theSame;
}

//---------------------------------------------------------------------------
